<?php

require '../utils/conn.php';
include_once '../models/topic.php';

function getTopicById($tid) {
	if ($tid == -1) {
		return null;
	}
	$query = "SELECT * FROM t_topic WHERE t_id = ".$tid;
	$result = mysql_query($query)  or die("查询单词出现错误：". mysql_error());
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	$topic = new Topic();
	$topic->setTopicId($row['t_id']);
	$topic->setContent($row['t_content']);
	$topic->setTitle($row['t_title']);
	$content = str_replace("\"","'",$topic->content);
	$topic->setContent($content);
	$topic->setType($row['t_type']);
	$topic->setTimestamp($row['t_timestamp']);
	return $topic;
}

function getTopicBaseInfoById($tid) {
	if ($tid == -1) {
		return null;
	}
	$query = "SELECT t_id,t_type,t_timestamp FROM t_topic WHERE t_id = ".$tid;
	$result = mysql_query($query)  or die("查询单词出现错误：". mysql_error());
	$row = mysql_fetch_array($result, MYSQL_ASSOC);
	$topic = new Topic();
	$topic->setTopicId($row['t_id']);
	$topic->setType($row['t_type']);
	$topic->setTitle($row['t_title']);
	$topic->setTimestamp($row['t_timestamp']);
	return $topic;
}